﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhomble.Data.Users;

namespace Rhomble.Data.Customers
{
	public class CustomerRepository : UserOnlyRepository, IRepository<Customer>
	{
		public CustomerRepository(string userName) : base(userName) { }

		public IQueryable<Customer> GetQuery()
		{
			return Context.Customers;
		}

		public void AddNew(Customer customer)
		{
			var user = GetCurrentUser();

			customer.CustomerPK = Guid.NewGuid();

			customer.CreatedDate = DateTime.Now;
			customer.CreatedBy = user.UserId;

			Context.Customers.AddObject(customer);
			SaveChanges();
		}

		public void Update(Guid customerID, Customer customer)
		{
			var entity = GetQuery()
							.WithID(customerID)
							.Single();

			entity.Name = customer.Name;
			SaveChanges();
		}
	}
}
